#include <iostream>
#include <algorithm>

using namespace std;
const int N = 310, M = 8010;
int n, m;
int ret;
struct node
{
	int x, y, z;
}e[M];
int fa[N];
bool cmp(node& a, node& b)
{
	return a.z < b.z;
}
int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void kk()
{
	for (int i = 1; i <= n; i++) fa[i] = i;

	sort(e + 1, e + 1 + m, cmp);

	for (int i = 1; i <= m; i++)
	{
		int x = e[i].x, y = e[i].y, z = e[i].z;

		int fx = find(x), fy = find(y);
		if (fx != fy)
		{
			ret = max(ret, z);
			fa[fx] = fy;
		}
	}
}
int main()
{
	cin >> n >> m;
	
	for (int i = 1; i <= m; i++) cin >> e[i].x >> e[i].y >> e[i].z;

	cout << n - 1 << " ";

	kk();
	
	cout << ret << endl;
	return 0;
}